<?php
//附件
class UbuttonController extends Controller
{
	
	public function actionidvideo()
	{
		$this->layout='pop';
		 
		$this->render('idvideo',array());
	}
	
	public function actionidpic()
	{
		$this->layout='pop';
			
		$this->render('idpic',array());
	}
    public function actionhardwareidpic()
    {
        $this->layout='pop';

        $this->render('hardwareidpic',array());
    }
	public function actionnewsid()
	{
		$this->layout='pop';
			
		$this->render('newsid',array());
	}
	public function actionbzvideo()
	{  
		$this->layout='pop';
       
		$this->render('bzvideo',array());
	}
    public function actionvideo()
	{  
		$this->layout='pop';
       
		$this->render('video',array());
	}
	public function actionspecial()
	{  
		$this->layout='pop';
       
		$this->render('special',array());
	}
	public function actionpic()
	{  
		$this->layout='pop';
		$this->render('pic',array("uclass"=>$_GET['uclass']));
	}
	public function actionlink()
	{  
		$this->layout='pop';
       
		$this->render('link',array());
	}
    public function actionreview()
    {
        $this->layout='pop';
        $moban = isset($_GET['moban'])?$_GET['moban']:1;
        $this->render('review',array('moban'=>$moban));
    }
	public function actionliver()
	{  
		$this->layout='pop';
        $arr=array();
		$arr=Yii::app()->db3->createCommand("select id,nickname from vd_live where id in(9321,9323,9325,9327,9339,9343,9347,9487,9589,9719,9721,9975,10185,10297,15809,15443,16533,18579)")->queryAll();
		foreach($arr as $key => $value){
  
               $data.='<input type="radio" '.($key==0 ? "checked" : "").' value="'.$value['id'].'" name="live"><a href="javascript:void(0)">'.$value['nickname'].'</a><br/>'; 

		}
		$this->render('liver',array("data"=>$data));
	}
	public function actionindexpic()
	{  
		$this->layout='pop';
       
		$this->render('indexpic',array());
	}
	public function actionxgnewsid()
	{  
		$this->layout='pop';
       
		$this->render('xgnewsid',array());
	}
	public function actionoloday()
	{  
		$this->layout='pop';
       
		$this->render('oloday',array());
	}
	public function actionsyzt()
	{  
		$this->layout='pop';
       
		$this->render('syzt',array());
	}
	public function actionh3()
	{  
		$this->layout='pop';
		$this->render('h3',array());
	}
    public function actiongamecard()
    {
        $this->layout='pop';
        $this->render('gamecard',array());
    }
	public function actionshop()
	{  
		$this->layout='pop';
       
		$this->render('shop',array());
	}
	public function actiontable()
	{
		$this->layout = 'pop';
		$this->render('table',array());
	}
	public function actionsygame()
	{  
		$this->layout='pop';
       
		$this->render('sygame',array());
	}
    public function actionpicedit()
    {
        $this->layout='pop';
        $this->render('picedit',array("class"=>$_GET['class']));
    }
    /*
     * module   1.ubutton   2.upf
     * 若修改js后无变化,需重置下assets时间,或去服务器把对应assets文件夹删了,让他重新生成
    */
    public function actionclearTime(){
        $module = isset($_GET['module'])?$_GET['module']:'ubutton';
        $time = time();
        $Y = date('Y',$time);
        $m = date('m',$time);
        $d = date('d',$time);
        $H = date('H',$time);
        $i = date('i',$time);
        $s = date('s',$time);
        touch(dirname(Yii::app()->BasePath)."/protected/modules/".$module."/assets",mktime($H,$i,$s,$m,$d,$Y));
    }
	//获取商品列表接口
	public function actiongetshoplist()
	{  
		$arr=array();
		/*$row=array();
		$row=Yii::app()->partner->createCommand("select name,pid from pt_extension where name like '%".addslashes($_GET['keyword'])."%' and `union_price`!='0.00' and status>0 order by addtime desc  limit 0,30")->queryAll();
		foreach($row as $key => $value){
			   $arr[$value['pid']]=array("id"=>$value['pid'],"name"=>$value['name']);
			   $idstr.=$idstr ? ",".$value['pid'] : $value['pid'];
		}
		if($idstr){
			$shoprow=Yii::app()->newshop->createCommand("select attr_value_id,id,products_id,price,outmainland from shop_commodity where id in(".$idstr.")")->queryAll();
			foreach($shoprow as $key => $value){
				   $arr[$value['id']]['url']="http://ali213.fhyx.hk/item/".$value['products_id'].".html".$this->attr_value_url($value['attr_value_id']);
				   $arr[$value['id']]['price']=$value['price'];
				   $arr[$value['id']]['outmainland']=$value['outmainland'];
			}
	    }*/
        $fhyxHtml = file_get_contents('https://img.fhyx.com/uploads/api/shop_maoxiu.js?r=' . date('YmdH', time()));
        $fhyxHtml = str_replace('var shop_json=', '', $fhyxHtml);
        $fhyxArr = json_decode($fhyxHtml, true);
        foreach ($fhyxArr as $value) {
            if($value['keyword'] and mb_stristr($value['keyword'],$_GET['keyword'])) {
                $oday=oday::model()->findByAttributes(array('keyword'=>$value['keyword']));
                if($oday){
                    $shopid = str_replace(array('https://ali213.fhyx.hk/item/', 'https://ali213.fhyx.com/item/', '.html?uf=fhyx'), '', $value['url']);
                    $arr[$shopid] = array(
                        'id' => $oday['ID'],
                        'name' => $value['commodity_name'],
                        'price' => $value['price'],
                        'url' => $value['url']
                    );
                }
            }
        }
		if(count($arr)==0) echo json_encode(0);
		else echo json_encode($arr);
		 
	}
	public function attr_value_url($attr_value_id){
		if($attr_value_id){
			
			if(strpos($attr_value_id,",")){
				$arr = explode(",",$attr_value_id);
				return '#attrone='.$arr[0].'&attrtwo='.$arr[1];
			}else{
				return '#attrone='.$attr_value_id;	
			}
			
		}else{
			return '';	
		}	
	}
	//获取手游专题接口
	public function actiongetsyzt()
	{  
		$arr=array();
		$row=array();
		$row=Yii::app()->db6->createCommand("select title,path from 0day where title like '%".addslashes($_GET['keyword'])."%' and issc=1 order by addtime desc  limit 0,30")->queryAll();
		foreach($row as $key => $value){
			   $arr[]=array("url"=>"http://m.ali213.net/".$value['path']."/","title"=>$value['title']);
		}
		if(count($arr)==0) echo json_encode(0);
		else echo json_encode($arr);
		 
	}
	//获取手游专题接口
	public function actiongetsygame()
	{  
		$arr=array();
		$row=array();
		$row=Yii::app()->db6->createCommand("select title,id from game where title like '%".addslashes($_GET['keyword'])."%' order by addtime desc  limit 0,30")->queryAll();
		foreach($row as $key => $value){
			   $arr[]=array("title"=>$value['title'],"id"=>$value['id']);
		}
		if(count($arr)==0) echo json_encode(0);
		else echo json_encode($arr);
		 
	}
	//获取专题接口
	public function actiongetspecial()
	{  
		$arr=$ztarr=$ltarr=$gmarr=$gxarr=$row=$syzt=array();
		//专题
		$row=Yii::app()->ali213_new->createCommand("select SpeName,GgeneratePath from gamesubject where Keyword=:Keyword order by AddTime desc limit 1")->queryRow(true,array(':Keyword' => $_GET['keyword']));
		if($row){
            $ztarr[0]['type']=1;
			$ztarr[0]['name']=$row['SpeName'];
			$ztarr[0]['url']="http://www.ali213.net/zt/".$row['GgeneratePath']."/";
		}
		//论坛
		$rs=Yii::app()->ali213_new->createCommand("select bbsurl,name from oday where keyword=:Keyword order by AddTime desc limit 1")->queryRow(true,array(':Keyword' => $_GET['keyword']));
		if($rs){
            $ltarr[0]['type']=2;
			$ltarr[0]['name']=$rs['name'];
			$ltarr[0]['url']=!empty($rs['bbsurl']) ? $rs['bbsurl'] : "http://game.ali213.net";
		}
		//商城
		$gmarr[]=shop_ads_data::getShopUrl($_GET['keyword'],$type=1);
		//共享
		$gxarr[]=share_game::getUrl($_GET['keyword']);
		//手游专题 jobs 2020-03-12  加了，但是没屌用，因为通过pc的关键词是不可能搜索到手游新报滴！！！！！
        $syztRow = Yii::app()->db6->createCommand('select title,path from zt where keyword=:keyword')->queryRow(true,array(':keyword' => $_GET['keyword']));
        if ($syztRow) $syzt[] = array('type' => 1,'name' => $syztRow['title'],'url' => 'https://m.ali213.net/'.$syztRow['path'].'/');
        $arr=array_merge($ztarr,$ltarr,$gmarr,$gxarr,$syzt);
		if(count($arr)==0) echo json_encode(0);
		else echo json_encode($arr);
	}
	//获取link接口
	public function actiongetlink()
	{  
		$arr=$row=array();
		if($_GET['type']=="special"){
                $arr=Yii::app()->ali213_new->createCommand("select SpeName,GgeneratePath from gamesubject where Keyword like '%".addslashes($_GET['keyword'])."%' order by AddTime desc  limit 0,30")->queryAll();
				foreach($arr as $key => $value){
		               $arr[$key]['url']="http://www.ali213.net/zt/".$value['GgeneratePath']."/";
		               $arr[$key]['title']=$value['SpeName'];
				}
		}else if($_GET['type']=="zhuanti"){
                $arr=Yii::app()->ali213_new->createCommand("select SubjectName,SubjectUrl from seriessubject where SubjectName like '%".addslashes($_GET['keyword'])."%' order by addtime desc  limit 0,30")->queryAll();
				foreach($arr as $key => $value){
		               $arr[$key]['url']=$value['SubjectUrl'];
		               $arr[$key]['title']=$value['SubjectName'];
				}
		}else if($_GET['type']=="oday"){
                $arr=Yii::app()->ali213_new->createCommand("select addtime,ID,name from oday where keyword like '%".addslashes($_GET['keyword'])."%' order by AddTime desc  limit 0,30")->queryAll();
				foreach($arr as $key => $value){
		               $arr[$key]['url']="http://0day.ali213.net/html/".date("Y",$value['addtime'])."/".$value['ID'].".html";
		               $arr[$key]['title']=$value['name'];
				}
		}elseif($_GET['type']=="injian")
		{
			$arr=Yii::app()->hardware->createCommand("select addtime,newsid,subject,classid from hardware_news where subject like '%".addslashes($_GET['keyword'])."%' order by addtime desc  limit 0,30")->queryAll();
			foreach($arr as $key => $value){
				$arr[$key]['url']="http://in.ali213.net/".$this->getFiledir($value["classid"])."/".date("Ym",$value["addtime"])."/".$value["newsid"].".html";
				$arr[$key]['title']=$value['subject'];
			}
		}elseif($_GET['type']=="syoday")
		{
			$arr=Yii::app()->db6->createCommand("select path,title from 0day where title like '%".addslashes($_GET['keyword'])."%' order by addtime desc  limit 0,30")->queryAll();
			foreach($arr as $key => $value){
				$arr[$key]['url']="http://m.ali213.net/".$value["path"]."/";
				$arr[$key]['title']=$value['title'];
			}
		}elseif($_GET['type']=="sygl")
		{
			$arr=Yii::app()->ali213_new->createCommand("select id,title,addtime from gl where title like '%".addslashes($_GET['keyword'])."%' and classid=13 order by addtime desc  limit 0,30")->queryAll();
			foreach($arr as $key => $value){
				$arr[$key]['url']=gl::getsyurl($value["id"],$value["addtime"]);
				$arr[$key]['title']=$value['title'];
			}
		}elseif($_GET['type']=="syzfl")
		{
			//hty 2019 11 19 添加链接子分类
			$arr = array();
			$arr1=Yii::app()->db6->createCommand("select path,id from 0day where title like '%".addslashes($_GET['keyword'])."%' order by addtime desc limit 0,30")->queryAll();
			foreach ($arr1 as $k => $v) {
				$arr2=Yii::app()->db6->createCommand("select title,path from 0day_diy_mod where oid = {$v['id']} and parentid = 0 order by addtime desc limit 0,30")->queryAll();
				foreach ($arr2 as $k1 => $v1) {
					$arr[]=array(
						'url'=>'https://m.ali213.net/'.$v['path'].'/'.$v1['path'].'/',
						'title'=>$v1['title'],
					);
				}
			}
		}
		else{
                $arr=Yii::app()->ali213_new->createCommand("select bbsurl,name from oday where keyword like '%".addslashes($_GET['keyword'])."%' order by AddTime desc limit 0,30")->queryAll();
				foreach($arr as $key => $value){
		               $arr[$key]['url']=!empty($value['bbsurl']) ? $value['bbsurl'] : "http://game.ali213.net";
		               $arr[$key]['title']=$value['name'];
				}
				
				

		}
		
		if(count($arr)==0) echo json_encode(0);
		else echo json_encode($arr);
		 
	}
	//获取新闻接口
	public function actiongetxgnews()
	{  
		$arr=$row=array();
		$arr=Yii::app()->ali213_new->createCommand("select ID,Title,addtime from news where isshow=1 and Title like '%".addslashes($_GET['keyword'])."%' order by addtime desc limit 0,30")->queryAll();
		foreach($arr as $key => $value){
            $ID = $value["ID"];
			if($ID < 19180){
				$nurl =  "http://www.ali213.net/news/html/".date("Y",$value["addtime"])."/".$ID.".html";
			}else{
				$nurl =  "http://www.ali213.net/news/html/".date("Y-n",$value["addtime"])."/".$ID.".html";
			}
			$arr[$key]["nurl"]=$nurl;
		}
		if(count($arr)==0) echo json_encode(0);
		else echo json_encode($arr);
	}
	
	function getFiledir($classid){
		switch ($classid) {
			case '1':
				return "news";
			case '2':
				return "pingce";
			case '3':
				return "buy";
			default:
				return "play";
		}
	}
	//获取图片列表
	public function actiongetpiclist()
	{  
		$where="";
		$arr=$row=array();
		if($_GET["type"] and $_GET["type"]!=3)
		{ 
			 $type = intval($_GET["type"]);
			 $where = " and type = ".$type;
		}
		
		$arr=Yii::app()->ali213_new->createCommand("select ID,indexpic,papername as name,Pic_Image from pic where keyword like '%".addslashes($_GET['keyword'])."%' ".$where." order by addtime desc limit 30")->queryAll();
		foreach($arr as $key => $value){
			   $Pic_Image_arr = explode("||", $value["Pic_Image"]);
			   $arr[$key]['indexpicpic']="http://images.ali213.net".$value['indexpic'];
               $arr[$key]['nums']= count($Pic_Image_arr)-1;
		}
		if(count($arr)==0) echo json_encode(0);
		else echo json_encode($arr);
		 
	}
	
	//获取图片列表
	public function actiongetpiclists()
	{
		$arr=$row=array();
		$arr=Yii::app()->ali213_new->createCommand("select ID as id,indexpic,papername as title,addtime from pic where papername like '%".addslashes($_GET['keyword'])."%' or  keyword like '%".addslashes($_GET['keyword'])."%' order by addtime desc limit 30")->queryAll();
		foreach($arr as $key => $value){
			$arr[$key]['indexpicpic']="http://images.ali213.net".$value['indexpic'];
			$arr[$key]["url"]="http://pic.ali213.net/html/".date("Y-m-d",$value["addtime"])."/".$value["id"].".html";
		}
		if(count($arr)==0) echo json_encode(0);
		else echo json_encode($arr);
			
	}

    //获取硬件图片列表
    public function actiongetdiypiclists()
    {
        $arr=$row=array();
        $arr=Yii::app()->hardware->createCommand("select  id,indexpic,  title,addtime from hardware_pic where title like '%".$_GET['keyword']."%' or  keyword like '%".$_GET['keyword']."%' order by addtime desc limit 30")->queryAll();
        foreach($arr as $key => $value){
            $arr[$key]['indexpicpic']="http://images.ali213.net".$value['indexpic'];
            $arr[$key]["url"]="http://in.ali213.net/pic/".date("ymd",$value["addtime"])."/".$value["id"].".html";
        }
        if(count($arr)==0) echo json_encode(0);
        else echo json_encode($arr);

    }


    //获取新闻列表
	public function actiongetnes()
	{
		$arr=$row=array();
		$where = "";
		if($_GET["type"]){
			$where ="Title like '%".$_GET['type']."%'  and ";
		}
		
		$arr=Yii::app()->ali213_new->createCommand("select ID as id,Title as title,addtime from news where ".$where." (Title like '%".addslashes($_GET['keyword'])."%' or  Keyword like '%".addslashes($_GET['keyword'])."%') order by addtime desc limit 30")->queryAll();
		foreach($arr as $key => $value){
			$arr[$key]['indexpicpic']="http://images.ali213.net".$value['indexpic'];
			$ID = $value["id"];
			if($ID < 19180){
				$url =  "http://www.ali213.net/news/html/".date("Y",$value["addtime"])."/".$ID.".html";
			}else{
				$url =  "http://www.ali213.net/news/html/".date("Y-n",$value["addtime"])."/".$ID.".html";
			}
			$arr[$key]["url"]=$url;
		}
		if(count($arr)==0) echo json_encode(0);
		else echo json_encode($arr);
			
	}

	//获取网游新报列表
	public function actiongetoloday()
	{
		
		$arr=array();

		$odayarr=ol_yxk::model()->findAllBySql("select id,title from ol_yxk where isshow=1 and title like '%".trim(addslashes($_GET['keyword']))."%'");

		foreach ($odayarr as $key => $value) {

			$arr[]=array("id"=>$value['id'],"title"=>$value['title']);

		}
				if(count($arr)==0) echo json_encode(0);
		else echo json_encode($arr);
			
	}
	
	
	public function actionhtmltoubb()
	{
		$this->layout='pop';
		$this->render('htmltoubb',array());
	} 
	
	//获取584图片
	public function actiongetpic()
	{  
		$this->layout='pop';
		$arr=$row=array();
		$arr=Yii::app()->ali213_new->createCommand("select Pic_Image1,Author from pic where ID='".intval($_GET['id'])."'")->queryRow();
		if($arr["Author"]=="sys")$arr['Pic_Image1']=str_replace("584_", "", $arr['Pic_Image1']);
		$row=explode("||", $arr['Pic_Image1']);
		array_shift($row);
		$this->render('getpic',array("row"=>$row));
		 
	}

	//获取视频列表
	public function actiongetvideolist()
	{  
		$this->layout='pop';
		$data=$arr=$row=array();

		$arr=Yii::app()->db3->createCommand("select id,addtime,vid,sourceid,title,letv_unique,flash from vd_video where title like '%".$_GET['keyword']."%' or keyword='".$_GET['keyword']."' and (sourceid=1 or sourceid=4 or sourceid=9) and typeid=1 order by addtime desc limit 30")->queryAll();

        foreach($arr as $value){
		          $row['id']=$value['id'];
			      $row['vid']= $value['sourceid']=="9" ? $value['letv_unique'] : $value['vid'];
			      $row['flash'] = $value['flash'];
				  $row['title']=$value['title'];
				  $row['type']=$value['sourceid']==1 ? "youku" : ($value['sourceid']==9 ? "letv" :
                      ($value['sourceid']==10 ? "youkunew" : ($value['sourceid']==2 ? "bilibili" : "tudou")));
				  $row['url']="http://v.ali213.net/video/".substr(date("Ymd",$value['addtime']),-6)."/".$value['id'].".html";
				  $row['key']=md5("alikey".$value['vid']."zrm");
				  array_push($data,$row);
		}
		if(count($data)==0) echo '0';
		else echo json_encode($data);
		 
	}

	//获取表格列表
	public function actiongettablelist()
	{  
		$this->layout='pop';
		$data=$arr=$row=array();
		$where = '';
		if($_GET['type'] != 0){
			$where = ' and type = '.$_GET['type'];
		}
		$arr=Yii::app()->ali213_new->createCommand("select id,title,content,type from gl_table where (title like '%".addslashes($_GET['keyword'])."%' or keyword='".addslashes($_GET['keyword'])."')".$where." order by addtime desc limit 30")->queryAll();
        foreach($arr as $value){
			$row['title']=$value['title'];
			$row['content']=str_replace("<table","<table data-table='".$value['id']."'",$value['content']);
			array_push($data,$row);
		}
		if(count($data)==0) echo '0';
		else echo json_encode($data);
		 
	}

	
	
}